% # variable:
% # ehistory, mtime, record_name

% import datetime as DT

% time_format_from = '%Y-%m-%dT%H:%M:%S.%f%z'
% time_format_to = '%Y-%m-%d %H:%M:%S'

<ul class="menuroot">
    <!-- Current Version -->
    % if not record_name:
        %cls = 'target'
    % else:
        %cls = ''
    % end

    <li id="current_version"><a class="{{cls}}" title="Current Version: {{mtime.strftime(time_format_to)}}" href=".">Current Version<br><span id="current_version_time">{{mtime.strftime(time_format_to)}}</span><span class="notify-small"><img class="icon" src="/static/icon/sidebar/time.svg"></span></a>

        <!-- Records -->
        %if ehistory is not None:
            %records = sorted(ehistory, key = lambda e: e.findtext('./frozen_time'), reverse = True)
            %if len(records):
                <ul id="recordList">

                %for record in records:
                    %name = record.get('name')
                    %frozen_time_text = record.findtext('./frozen_time')
                    %frozen_time = DT.datetime.strptime(frozen_time_text, time_format_from)
                    %comment = record.findtext('./comment')
                    %if name == record_name:
                        %cls = 'target'
                    %else:
                        %cls = ''
                    %end
                    <li id="{{name}}" title="Frozen time: {{frozen_time.strftime(time_format_to)}}">
                        <a class="{{cls}}" href="?record_name={{name}}">{{comment}}</a>
                        <!-- 對單項歷史記錄的操作 -->
                        <ul>
                            <li title="Delete the history record." onclick="lo.noteop.record_del_dia('{{name}}', '{{comment}}');"><a>delete</a></li>
                        </ul>
                    </li>
                %end
                </ul>
            %end
        %end
    </li>
</ul>

